// components/custom-swiper/index.js
Component({
    /**
     * 组件的属性列表
     */
    properties: {
        type: {
            type: String,
            value: 'none'
        },
        height: {
            type: String,
            value: '410'
        },
        // 轮播数据列
        swiperList: {
            type: Array,
            value: []
        },
        // 是否显示内置只是标点
        isDots: {
            type: Boolean,
            value: false
        },
        // 内置默认指示点颜色
        inDotsColor: {
            type: String,
            value: 'rgba(0, 0, 0, .5)'
        },
        // 内置默认当前选中指示点颜色
        inDotsActiveColor: {
            type: String,
            value: '#FFF'
        },
        // 是否开启自动轮播模式
        autoplay: {
            type: Boolean,
            value: true
        },
        preview: {
            type: Boolean,
            value: false
        },
        describe: {
            type: String,
            value: ""
        },
        //是否是广告位
        isAdv: {
            type: Boolean,
            value: false
        }
    },

    /**
     * 组件的初始数据
     */
    data: {
        current: 0, // 当前轮播索引值
        currentSwiper: 0,
        autoplay: "", // 自动轮播状态
        isDots: "",
        inDotsColor: "",
        inDotsActiveColor: "",
        previewAutoplay: false,
        isPreview: false,
        open: false,
        isAdv: false,
        currentPreviewImg:{}
    },
    /**
     * 组件属性监听
     */
    observers: {
        'preview': function (e) {
            this.setData({
                isPreview: e
            })
        },
        'swiperList': function(newVal){
            if(Array.isArray(newVal)&&newVal.length){
                this.setData({
                    currentPreviewImg: newVal[0]
                })
            }

        }
    },
    /**
     * 组件的方法列表
     */
    methods: {
        swiperChange: function(e) {
            this.setData({
                currentSwiper: e.detail.current,
                currentPreviewImg: this.data.swiperList[e.detail.current]
            })
        },
        //监听轮播图回调函数方法
        monitorCurrent: function (e) {
            let current = e.detail.current;
            this.setData({
                current: current,
                
            })
        },
        /**
         * 点击图片回调函数方法
         */
        handleClickImg(e) {
            console.log('e',e)
            if (this.data.isAdv) {
                this.handleRegionEntry(e)
            } else {
                if (this.data.isPreview) {
                    this.setData({
                        previewAutoplaya: false,
                        open: !this.data.open
                    })
                    this.triggerEvent('customtap', this.data.open)
                }
            }
        },
        /**
         * 关闭预览
         */
        handlePreviewClose() {
            this.setData({
                open: false
            })
        },
        previewCurrent(e) {
            console.log(e);
        },
        /**
         * 根据条件跳转各项活动专区回调函数方法
         */
        handleRegionEntry(e) {
            const {
                value
            } = e.currentTarget.dataset;
            let num = value.type
            let id = value.type
            const params = {
                name: value.name,
                value: value
            }
            // 根据类型判断跳转到具体的链接
            if (num == 1) {
                // params.name = '9.8'
                // wx.navigateTo({
                //     url: `/pages/goods_indulgence/index?data=${JSON.stringify(params)}`,
                // })
            }
            // 根据类型判断跳转到具体的链接
            if (num == 2) {
                params.name = '特卖专区'
                wx.navigateTo({
                    url: `/pages/goods_indulgence/index?data=${JSON.stringify(params)}`,
                })
            }
            if (num == 4) {
                // params.name = '特卖专区'
                params.value.goodsId =  params.value.goodsid
                params.value.detailType = 1,
                params.value.act ="good_detail"
               
                wx.navigateTo({
                    url: `/pages/goods_detail/index?data=${JSON.stringify(params.value)}`,
                })
            }
            // 根据类型及活动ID同时判断前往对应条件页
            if (num == 3 && value.activeid) {
                let obj = {
                    ...value,
                }
                obj.bcat_list.forEach(element => {
                    Object.assign(element,{
                        objType:0
                    })
                });
                obj.pettype_list.forEach(element => {
                    Object.assign(element,{
                        objType:1
                    })
                });
                obj.name = obj.brandname
                obj.brand_list = [...obj.brand_list,...obj.bcat_list,...obj.pettype_list]
                let objStr = encodeURIComponent(JSON.stringify(obj));
                wx.navigateTo({
                    url: '/pages/goods_list/index?obj=' + objStr,
                })
            }
            if (num == 7) {
                wx.navigateTo({
                    url: `/pages/new_born_zone/index?data=${JSON.stringify(params)}`,
                })
            }
            // 根据类型判断前往新品专区
            if (num == 8) {
                params.name = '新品专区'
                wx.navigateTo({
                    url: `/pages/goods_indulgence/index?data=${JSON.stringify(params)}`,
                })
            }
            if (num == 9) {
                params.name = '特卖专区'
                wx.navigateTo({
                    url: `/pages/goods_indulgence/index?data=${JSON.stringify(params)}`,
                })
            }
            if (num == 10) {
                params.name = '限时秒杀'
                wx.navigateTo({
                    url: `/pages/mall_flash_sale/index?data=${JSON.stringify(params)}`,
                })
            }
            if (num == 11) {
                params.name = '品牌促销'
                wx.navigateTo({
                    url: `/pages/brand_list/index?data=${JSON.stringify(params.value)}`,
                })
            }
            if (num == 12) {
                params.name = '换购专区'
                wx.navigateTo({
                    url: `/pages/goods_more_lists/index?data=${JSON.stringify(params)}`,
                })
            }
            if (num == 13) {
               let  title='优惠券专区'
                // params.name = '优惠券专区'
                wx.navigateTo({
                    url: `/pages/coupon/index?title=${title}` + '&lin=' + 1,
                })
            }
            // 根据类型判断前往一件代发
            if (num == 14) {
                let obj = {
                    ...params,
                    shipping: true
                }
                let objStr = encodeURIComponent(JSON.stringify(obj));
                wx.navigateTo({
                    url: '/pages/goods_list/index?obj=' + objStr,
                })
            }
           
            if ( num == 17) {
    
                params.value.goodsId =  params.value.goodsid
                params.value.detailType = 1,
                params.value.lack_inventory = 1,
                params.value.act ="special_sales_detail"
               
                wx.navigateTo({
                    url: `/pages/goods_detail/index?data=${JSON.stringify(params.value)}`,
                })
            }
            if (num == 16 ) {
                
                params.value.goodsId =  params.value.goodsid
                params.value.detailType = 10,
                params.value.act ="seckill_detail"
               
                wx.navigateTo({
                    url: `/pages/goods_detail/index?data=${JSON.stringify(params.value)}`,
                })
            }
          
            if (num == 18) {
                
                params.value.goodsId =  params.value.goodsid
                params.value.detailType = 7,
                params.value.act ="unconsume_region_detail"
          
                wx.navigateTo({
                    url: `/pages/goods_detail/index?data=${JSON.stringify(params.value)}`,
                })
            }
            if (num == 19) {
               
                params.value.goodsId =  params.value.goodsid
                params.value.detailType = 8,
                params.value.lack_inventory = 1,
                params.value.act ="new_goods_region_detail"
          
                wx.navigateTo({
                    url: `/pages/goods_detail/index?data=${JSON.stringify(params.value)}`,
                })
            }
            // 根据类型及活动ID同时判断前往对应条件页
            if (num == 20 && value.activeid) {
                wx.navigateTo({
                    url: `/pages/goods_more_lists/index?data=${JSON.stringify(params)}`,
                })
            }
        },

    }
})